package com.design_mode;

import com.sun.xml.internal.stream.buffer.AbstractCreator;

/**
 * Created by dustaple on 2014/7/30.
 */
public class AbstractFactoryPattern {

    public static void main(String[] args) {
        AbstractCreatorA creatorA = new CreatorA();
        AbstractCreatorB creatorB = new CreatorB();
        AbstractProductA productA = creatorA.createProductA();
        AbstractProductB productB = creatorB.createProductB();
    }
}

abstract class AbstractProductA {
    String codeA;
    ;

    abstract String sayA();
}

abstract class AbstractProductB {
    String codeB;

    abstract String sayB();
}

class ProductA extends AbstractProductA {
    @Override
    String sayA() {
        return "I'm product A.";
    }
}

class ProductB extends AbstractProductB {
    @Override
    String sayB() {
        return "I'm product B.";
    }
}

interface AbstractCreatorA {
    AbstractProductA createProductA();
}

interface AbstractCreatorB {
    AbstractProductB createProductB();
}

class CreatorA implements AbstractCreatorA {
    @Override
    public AbstractProductA createProductA() {
        return new ProductA();
    }
}

class CreatorB implements AbstractCreatorB {
    @Override
    public AbstractProductB createProductB() {
        return new ProductB();
    }
}